package com.javasm.springmybatis.task;

import com.javasm.springmybatis.config.TestThreadPoolTaskExecutor;
import com.javasm.springmybatis.entity.Admin;
import com.javasm.springmybatis.service.IAdminService;
import com.javasm.springmybatis.sync.AsyncFactory;
import com.javasm.springmybatis.sync.AsyncManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：zzt
 * @Version：1.0
 * @Date：2021/11/9-22:38
 * @Since:jdk1.8
 * @Description:
 */
@Component
public class MySendEmailTask {
    @Resource
    private IAdminService adminService;

    @Resource
    private TestThreadPoolTaskExecutor testThreadPoolTaskExecutor;

    @Resource
    private AsyncTask asyncTask;

//    @Scheduled(cron = "0/5 * * * * *")
    public void sendEmail(){
        adminService.selectList().forEach(admin -> {
            AsyncManager.getInstance().execute(AsyncFactory.sendEmail(admin.getEmail(),"可以的"));
        });
    }


//    @Scheduled(cron = "0/1 * * * * *")
    public void set(){
//        asyncTask.register();
        testThreadPoolTaskExecutor.execute(asyncTask.ss());
    }

    @Scheduled(cron = "0/1 * * * * *")
    public void set2(){
        asyncTask.register2();
    }



}
